IS NULL Condition

Course- MariaDB >

This MariaDB tutorial explains how to use the MariaDB IS NULL condition with syntax and examples.

Description

The MariaDB IS NULL condition is used to test for a NULL value in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax

The syntax for the IS NULL condition in MariaDB is:

expression IS NULL

Parameters or Arguments

expression

The value to test whether it is a NULL value.

Note

  • If expression is a NULL value, the condition evaluates to TRUE.
  • If expression is not a NULL value, the condition evaluates to FALSE.
  • See also the IS NOT NULL condition in MariaDB.

Example - With SELECT Statement

Let's look at an example of how to use the IS NULL condition in a SELECT statement in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_name IS NULL;

This MariaDB IS NULL example will return all records from the sites table where the site_name contains a NULL value.

Example - With INSERT Statement

Next, let's look at an example of how to use the IS NULL condition in an INSERT statement in MariaDB.

For example:

INSERT INTO contacts

(contact_id, contact_name)

SELECT site_id, site_name

FROM sites

WHERE site_name = 'Fastread.aitechtonic.com'

AND server_name IS NULL;

This MariaDB IS NULL example will insert records into the sites table where the site_name is 'Fastread.aitechtonic.com' and the server_name contains a NULL value.

Example - With UPDATE Statement

Next, let's look at an example of how to use the IS NULL condition in an UPDATE statement in MariaDB.

For example:

UPDATE sites

SET site_name = 'Fastread.aitechtonic.com'

WHERE site_name IS NULL;

This IS NULL condition example will update records in the sites table where the site_name contains a NULL value.

Example - With DELETE Statement

Next, let's look at an example of how to use the IS NULL condition in a DELETE statement in MariaDB.

For example:

DELETE FROM sites

WHERE server_name IS NULL;

This IS NULL example will delete all records from the sites table where the server_name contains a NULL value.